import BaseManager from "./BaseManager";
import CameraControl from "../game/Camera/CameraControl";
import LevelBaseControl from "../game/LevelCommon/LevelBaseControl";
import { LevelData } from "../game/Data/LevelData";

/**
 * 关卡管理
 */
export default class LevelManager extends BaseManager {

    /** 当前的关卡*/
    private curLevelControl: LevelBaseControl;

    /** 当前的关卡数据*/
    private curLeveldata: LevelData;

    /** 获得当前的关卡*/
    public GetCurLevelControl(): LevelBaseControl {
        return this.curLevelControl;
    }

    /** 获得当前关卡数据*/
    public GetCurLevelData(): LevelData {
        return this.curLeveldata;
    }

    /** 设置当前关卡*/
    public SetCurLevel(curLevelControl: LevelBaseControl): void {
        this.curLevelControl = curLevelControl;
    }

    /** 获得当前关卡的相机*/
    public GetCurLevelCamera(): CameraControl {
        let curLevel = this.GetCurLevelControl();
        if (curLevel != null) {
            return curLevel.GetCameraControl();
        }
        else {
            return null;
        }
    }

    /** 进入关卡*/
    public PlayInLevel(levelData: LevelData): void {
        this.curLeveldata = levelData;
        /** 进入关卡场景*/
        window.gameFacade.SceneMng.EnterGameScene(levelData);
    }
    
    /** 下一关*/
    public PlayInNextLevel(): void {
        if (this.curLevelControl != null) {
            let nextLevelData: LevelData = window.gameFacade.ConfigMng.GetLevelDataByLevelNum(this.curLeveldata.levelNum + 1);
            if (nextLevelData != null) {
                this.PlayInLevel(nextLevelData);
            }
            else {
                window.gameFacade.SceneMng.EnterMainScene(null);
            }
        }
    }
    
    /** 退出关卡*/
    public QuitLevel(): void {
        /** 回到初始场景*/
        window.gameFacade.SceneMng.EnterMainScene(null);
    }
}
